#include "stm32f10x.h"                  // Device header
#include "dma.h"

uint8_t Dma_buf[Size] = {"111"};
//uint8_t* Dma_buf1 = Dma_buf;

void My_DMA_Init(void)
{
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
	
	DMA_InitTypeDef   DMA_InitStruct;
	DMA_DeInit(DMA1_Channel5);
	DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(USART1->DR);
	DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)U1_RXData;
//	DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)Dma_buf1;
	DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
	DMA_InitStruct.DMA_BufferSize = U1_RX_MAX+10;
	DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
	DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
	DMA_Init(DMA1_Channel5 ,&DMA_InitStruct);
	
//	USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
	
	DMA_Cmd(DMA1_Channel5,ENABLE);
}

//void USART1_DMA_TXD(int x)
//{
//	DMA_Cmd(DMA1_Channel4,DISABLE);
//	DMA_SetCurrDataCounter(DMA1_Channel4,x);
//	DMA_Cmd(DMA1_Channel4,ENABLE);
//	while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
//	DMA_ClearFlag(DMA1_FLAG_TC4);
//}

void USART1_DMA_TXD()
{
	DMA_Cmd(DMA1_Channel4,DISABLE);
	DMA_SetCurrDataCounter(DMA1_Channel4,Size);
	DMA_Cmd(DMA1_Channel4,ENABLE);
	while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
	DMA_ClearFlag(DMA1_FLAG_TC4);
}



